package com.darry.firstspringboot;

import java.util.FormatFlagsConversionMismatchException;
import java.util.Iterator;

/**
 * @ProjectName firstspringboot
 * @Description: 冒泡排序
 * @Author darry
 * @Date 2019/1/23 8:50
 * @Version 1.0
 */
public class BubbleSort {



  

    /**
     *
     * @Author darry
     * @Description //TODO
     * @Date 2019/1/23 9:19
     * @Param
     * @param args
     * @return void
     **/
    public static void main(String[] args) {
        int[] arr = {1,6,9,3,5,8};
        System.out.println("排序前的顺序：");
        for (int i : arr) {
            System.out.print(i+" ");
        }
        for (int i = 0; i <arr.length - 1 ; i++) { //外循环控制趟数
            for (int j = 0; j < arr.length-1-i ; j++) { //内循环控制比较次数
                if(arr[j]>arr[j+1]){
                    int temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                }

            }

        }
        System.out.println();
        System.out.println("排序后的顺序：");
        for (int i : arr) {
            System.out.print(i+" ");
        }
    }
    
}
